package com.xm.servlet.background.departments;

import com.google.gson.Gson;
import com.xm.service.background.DepartmentsService;
import lombok.SneakyThrows;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 职称Servlet
 *
 * @author 陈盼
 * @date 2023-01-10 下午 6:50
 */
@WebServlet("/background/get/departments")
public class GetDepartmentsServlet extends HttpServlet {
    private final DepartmentsService service = new DepartmentsService();

    @SneakyThrows(Exception.class)
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        resp.getWriter().print(new Gson().toJson(service.getAll()));
    }
}
